package com.javaspeak.designpatterns.go4.creational.builder;

/**
 * Output looks like:
 * <p>
 * <p>  1111
 * <p>  1  1 1
 * <p>  1  11 1
 * <p>  1111   1
 * <p>    1111111
 * <p>
 * A Triangle is super imposed over the right and bottom sides of the square
 * <p>
 * This application uses a buildManager which calls constructShape(..) on
 * different builders to construct different shapes. The class Shape is used
 * to encapsulate shapes.   SquareBuilder and TriangleBuilder are used to
 * populate Shape with the correct values for a Square and Triangle
 * respectively.
 * <p>
 * The constructShape(..) method calls several methods on the builders to
 * build a shape.  The constructShape(..) method of the buildManager calls
 * the builder methods in the correct order:
 * <p>
 * <p>    shapeBuilder.setName();
 * <p>    shapeBuilder.setPaintingLevel();
 * <p>    shapeBuilder.buildPoints();
 * <p>    shapeBuilder.translateCoordinates();
 * <p>
 * The name is the name of the shape, e.g. triangle.
 * <p>
 * The paintinglevel is the order to paint the shape. For example any shape
 * with level 0 will be painted before any shape with level 1.
 * <p>
 * shapeBuilder.buildPoints() builds the points for the shape.
 * <p>
 * translateCoordinates() translates the points. e.g. it can
 * move a shape both vertically and horizontally.
 *
 * @author John Dickerson
 */
public class ApplicationBuilder {


    /**
     * Constructs the Shapes using the SquareBuilder and TriangleBuilder and
     * then merges their coordinates together into a points array in
     * BuildManager and then finally paints the merged points.
     */
    public void render(){

        BuildManager buildManager = new BuildManager();
        buildManager.constructShape( new SquareBuilder() );
        buildManager.constructShape( new TriangleBuilder() );
        buildManager.mergeCoordinates();
        buildManager.paint();
    }


    /**
     * Main method
     *
     * @param args
     */
    public static void main(String[] args) {

        ApplicationBuilder application = new ApplicationBuilder();
        application.render();
    }
}
